package handler

import (
	"context"

	"catering_sys_api/cmd/api/biz/business/model/login"
	"catering_sys_api/cmd/api/biz/business/service"
	"catering_sys_api/core/errno"

	"github.com/cloudwego/hertz/pkg/app"
)

type LoginHandler struct {
}

// 商户端账号密码登录
func (l *LoginHandler) PhoneLogin(ctx context.Context, c *app.RequestContext) {
	var (
		request      login.PhoneLoginRequest
		response     login.PhoneLoginResponse
		LoginService *service.LoginService
		err          error
	)
	err = c.BindAndValidate(&request)
	if err != nil {
		errno.Fail(errno.HTTP_PARAM_MISS, "", err.Error(), ctx, c)
		return
	}
	LoginService = service.NewLoginService(ctx, c)
	response, err = LoginService.PhoneLogin(request)
	if err != nil {
		errno.Fail(errno.HTTP_PARAM_MISS, "", err.Error(), ctx, c)
		return
	}
	errno.Ok(response, "", ctx, c)
	return
}
